<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link href="${aier_css_url}jq/jq.css" rel="Stylesheet" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}text.css" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}enhanced.css" />
<link rel="stylesheet" href="${aier_css_url}school/ma.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/dialog.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}jt/td.js"></script>

<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/arrayList.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/multiselect.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}custominput.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/afu.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}text.js"></script>
<title>主料图片管理</title>

<script type="text/javascript">
var num;
$(document).ready(function(){          
	$("#zhuliaoinfo").jqGrid({                
		url:'${aier_url}${aier_urijs}caipu_loadZhuLiao${aier_suffix}',                
		datatype:"json",                
		mtype:'GET', 
		height:'400',
		width:'400',                 
		colNames:['名称','图片','操作','img','id'],                
		colModel:[                    
		{name:'zl_name',index:'zl_name',width:100,align:'center', sortable:false},
		{name:'imginfo',index:'imginfo',width:160,align:'center', sortable:false},
		{name:'option',index:'zl_id',width:100,align:'center', sortable:false},
		{name:'zl_img',index:'zl_img',hidden:true},
		{name:'zl_id',index:'zl_id',hidden:true}
		],
		//autowidth:true,
		jsonReader: {
			root:"zhuliaoList",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery("#zhuliaopage"),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		hidegrid: false,
		viewrecords: true,
		caption: '主料',
		gridComplete:function(){
			var ids=jQuery("#zhuliaoinfo").jqGrid('getDataIDs');
			for(var i=0; i<ids.length; i++){
				var id=ids[i];   
				var imgName = jQuery("#zhuliaoinfo").jqGrid('getRowData', id).zl_img;
				var img_url = "${imgUrl}"+imgName;
				del = "<a href='javascript:;' class='jqtrow' onclick='upimg(" + id + ")'>修改</a>";
				if(imgName!=null&&imgName!=""){
					imginfo = "<a href='"+img_url+"' class='jqtrow' target='_blank'><img src='"+img_url+"' height='40px' width='50px'></a>";
				}else{
					imginfo = "";
				}
				jQuery("#zhuliaoinfo").jqGrid('setRowData', ids[i], {imginfo:imginfo,option:del});
			}
		}
	}).navGrid("#zhuliaopage", { edit: false, add: false, del: false, search: false });
});

function upimg(id){
	var zl_id = jQuery("#zhuliaoinfo").jqGrid('getRowData', id).zl_id;
	var fun = function(data) {
		num = data.zhuliao.zl_id;
		var zl_img_tmp = data.zhuliao.zl_img;
		if(zl_img_tmp!=null&&zl_img_tmp!=""){
			$("#zl_file0").attr("src","${imgUrl}" + zl_img_tmp);
		}
		$('#txt_pmupdname').val(data.zhuliao.zl_name); 
		$("#img_zl_0").val(zl_img_tmp);
		$("#zl_id").val(zl_id);
	};
	exeAjax(ajaxUrl("${aier_url}${aier_urijs}caipu_showZhuLiao${aier_suffix}"), fun,
		{"zl_id" : zl_id});	
	$("#d_pmupdateinfo").dialog("open");
}

//修改主料图片
function update(){
	var zl_img = $('#img_zl_0').val();		
	var zl_id = $("#zl_id").val();
	var fun = function(data) {
		if(1==data.s){
			$().message("修改成功!");
			$("#zhuliaoinfo").trigger("reloadGrid");
		}else{
			$().message("修改失败");
		}
	};
	exeAjax(ajaxUrl("${aier_url}${aier_urijs}caipu_updateZhuLiao${aier_suffix}"), fun, 
		{"zl_id" : zl_id,"zl_img" :zl_img});	
}
function closeD(){
	$("#d_pmupdateinfo").dialog("close");
}
</script>
</head>
<body>

	<div id="tabs">
		<div id="tabs-1" style="height: 500px;">
			<div class="d_content">
				<div style="margin-top: 30px;margin-left: -50px;">
					<div class="d_scnOut">
						<div style="margin-top: 5px;margin-left: 50px;">
							<table id="zhuliaoinfo"></table>
							<div id="zhuliaopage"></div>
						</div>									
					</div>
				</div>
				
			</div>
		</div>
	</div>
	
	<!-- 弹出层内容 -->
	<div id="d_pmupdateinfo" title="修改主料图片">
		<div class="d_scnOut">
			<div class="d_scname">
				<label for="txt_pmupdname">主料名称:</label>
			</div>
			<div class="d_sctext">
				<input type="text" id="txt_pmupdname" class="txt_scname" readonly="readonly">
			</div>
		</div>
		<div class="d_scnOut">
			<div class="d_scname">
				<label for="txt_pmupbrief">图片:</label>
			</div>
			<div class="d_sctext">
				<img id='zl_file0' width='200' height='150'>
				<input id='fileZL' type='file' name='fileZL' />
				<button onclick='upfile(-1);'>上传新图片</button>
				<input type='hidden' id='img_zl_0' /> 
				<input type='hidden' id='zl_id' /> 
				<br>
				<button onclick="update();">修改</button>
				<button onclick="closeD();">关闭</button>
			</div>

		</div>
		
	</div>
	
</body>
<script type="text/javascript">
$("#tabs").tabs();

function upfile(zl_rid) {
	try {$.ajaxFileUpload({
			url : "${aier_url}${aier_urijs}caipu_upfile${aier_suffix}?num=${num}&rownum="+zl_rid,
			secureuri : false,
			fileElementId : 'fileZL',
			dataType : 'json',
			success : function(data) {
				$("#zl_file0").attr("src","${imgUrl}" + data.imgName);
				$("#img_zl_0").val(data.imgName);
			},
			error : function(data, e) {
				$().message("上传失败");
			}
		});
	} catch (e) {
		$().message("服务器连接超时");
	}
}

// 弹出层
$(function() {

	$("#d_pmupdateinfo").dialog({
		//背景变暗
		modal: true,
		autoOpen : false,
		show : "blind",
		//hide : "explode",
		width : "450",
		height : "350"
	});

});

</script>

</html>